package thread;

public class SyncDemo4 {
    public static void main(String[] args) {
        Boo boo=new Boo();
        new Thread(boo::methodA).start();
        new Thread(boo::methodB).start();
    }
}
class Boo{
    public synchronized void methodA(){
        try {
            Thread t=Thread.currentThread();
            System.out.println(t.getName()+":正在执行methodA");
            Thread.sleep(2000);
            System.out.println(t.getName()+":methodA执行完毕");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    public void methodB(){
        try {
            synchronized (this) {
                Thread t=Thread.currentThread();
                System.out.println(t.getName()+":正在执行methodB");
                Thread.sleep(2000);
                System.out.println(t.getName()+":methodB执行完毕");
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
